package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryBillSendAddDTO;
import org.jsola.hr.dto.SalaryBillSendUpdateDTO;
import org.jsola.hr.entity.SalaryBillSendDO;
import org.jsola.hr.query.SalaryBillSendQuery;
import org.jsola.hr.service.ISalaryBillSendService;
import org.jsola.hr.vo.SalaryBillSendVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工资条发放信息
 *
 * @author zhr
 */
@Component
public class SalaryBillSendTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryBillSendService salaryBillSendService;

    /**
     * 生成add测试数据
     * @return SalaryBillSendAddDTO
     */
    public SalaryBillSendAddDTO getSalaryBillSendAddDTO(){
        SalaryBillSendAddDTO salaryBillSendAddDTO = new SalaryBillSendAddDTO();
        salaryBillSendAddDTO.setTableId(getRandomValue("varchar",32));
        salaryBillSendAddDTO.setSendType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryBillSendAddDTO.setAutoCheckHours(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setAutoCheckUnit(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryBillSendAddDTO.setShowEmptyValue(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillSendAddDTO.setSendName(getRandomValue("varchar",255));
        salaryBillSendAddDTO.setSendBy(getRandomValue("varchar",255));
        salaryBillSendAddDTO.setSendTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryBillSendAddDTO.setSendCount(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setReadCount(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setCheckCount(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setFeedbackCount(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setWithdrawnCount(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBillSendAddDTO.setWithdrawStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillSendAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryBillSendAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryBillSendUpdateDTO
     */
    public SalaryBillSendUpdateDTO getSalaryBillSendUpdateDTO(SalaryBillSendVO salaryBillSendVO){
        return salaryBillSendService.selectDOById(salaryBillSendVO.getId(), SITE_ID).to(SalaryBillSendUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryBillSendQuery
     */
    public SalaryBillSendQuery getSalaryBillSendQuery() {
        SalaryBillSendQuery salaryBillSendQuery = new SalaryBillSendQuery();
        List<SalaryBillSendDO> salaryBillSendDOList = salaryBillSendService.list(new SalaryBillSendDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryBillSendDOList)) {
            SalaryBillSendDO salaryBillSendDO = salaryBillSendDOList.get(0);
            salaryBillSendQuery = salaryBillSendDO.to(SalaryBillSendQuery.class);
            if (salaryBillSendDO.getSendTime() != null) {
                salaryBillSendQuery.setSendTimeStart(DateKit.getBeforeDay(salaryBillSendDO.getSendTime(),-1));
                salaryBillSendQuery.setSendTimeEnd(DateKit.getBeforeDay(salaryBillSendDO.getSendTime(),1));
            }
        }
        return salaryBillSendQuery;
    }

    /**
     * 保存示例
     * @return SalaryBillSendVO
     */
    public SalaryBillSendVO saveSalaryBillSendExample(){
        SalaryBillSendAddDTO addDTO = this.getSalaryBillSendAddDTO();
        SalaryBillSendVO salaryBillSendVO = salaryBillSendService.save(addDTO,buildTokenUser());
        return salaryBillSendVO;
    }


}

